package br.com.CONTROLE;

import java.io.File;
import br.com.DAO.ConsultaGeralDAO;
import br.com.DAO.LaudoObsDAO;
import javax.sql.rowset.serial.SerialException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import com.google.gson.Gson;

@Path("/SLLM")
public class Listaresource {
	// lista de consulta geral
	@GET
	@Path("/getlistaConsultageral")
	@Produces("application/json")
	public String getConsultageral() {
		// responsavel por converter arquivo java para Json e gerar um ArrayJson
		return new Gson().toJson(ConsultaGeralDAO.getlistaGeral());
	}

	@GET
	@Path("/getImagem")
	@Produces("imagem/jpg")
	public Response getImagem(@MatrixParam("exameid") int exameId,
		@MatrixParam("laudoid") int laudoId, @MatrixParam("obsid") int obsId) {
		File file = new File(LaudoObsDAO.BuscaFoto(exameId, laudoId, obsId));
		ResponseBuilder response = Response.ok((Object) file);
		response.header("Content-Disposition", "attachment; filename="
				+ exameId + "_" + laudoId + "_" + obsId + ".jpg");
		return response.build();
	}

	@GET
	@Path("/getListaobsid")
	@Produces(MediaType.TEXT_PLAIN)
	public String getListaImagem(@MatrixParam("exameid") int exameid) {
		return LaudoObsDAO.BuscaListaFoto(exameid).toString();
	}

	// metodo responsavel por pegar o laudoid e gravar o texto no banco de dados
	@POST
	@Path("/postComentario")
	@Consumes("text/plain")
	public void postComentario(@MatrixParam("laudoid") int laudoid,
			@MatrixParam("exameid") int exameid,
			@MatrixParam("obsid") int obsid,
			@MatrixParam("comentario") String comentario)
			throws SerialException {
		LaudoObsDAO.GravarTexto(laudoid, exameid, obsid, comentario);
	}
}